package net.lgpage.util;

import java.util.Calendar;
import java.util.Date;

import net.lgpage.util.FormatUtil.DateFormatUtil;

public class CompareUtil {

	public static class DateCompareUtil {

		public static long dayCompare(Calendar pre, Calendar next) {// ��
			long t1 = pre.getTimeInMillis();
			long t2 = next.getTimeInMillis();
			// ��������
			long days = (t2 - t1) / (24 * 60 * 60 * 1000);
			return days;
		}
		public static long dayCompare(Date pre, Date next) {// ��
			long t1 = pre.getTime();
			long t2 = next.getTime();
			// ��������
			long days = (t2 - t1) / (24 * 60 * 60 * 1000);
			return days;
		}

		public static int compare(Date od, Date dd) {
			int h1 = od.getHours();
			int m1 = od.getMinutes();
			int h2 = dd.getHours();
			int m2 = dd.getMinutes();
			return compare(h1, m1, h2, m2);
		}
		
		public static int compare(String shhmm,String ehhmm){
			String ss[] = shhmm.split(":");
			String es[] = ehhmm.split(":");
			int h1 = Integer.parseInt(ss[0]);
			int m1 = Integer.parseInt(ss[1]);
			int h2 = Integer.parseInt(es[0]);
			int m2 = Integer.parseInt(es[1]);
			return compare(h1, m1, h2, m2);
		}

		public static int compare(int h1, int m1, int h2, int m2) {
			if (h1 == h2) {
				return m1 - m2;
			} else {
				return h1 - h2;
			}
		}
		
		public static long minuteDiv(String timestamp){
			Date date = DateFormatUtil.convertTimeStamp(timestamp);
			Date now = new Date(System.currentTimeMillis());
			long between = (now.getTime() - date.getTime()) / 1000;// 除以1000是为了转换成秒
			long minute = between % 3600 / 60;
			return minute;
		}
		
		public static String leftMMss(Date date){
			if(date == null){
				return "00:00";
			}
			long between = (date.getTime()-System.currentTimeMillis()) / 1000;// 除以1000是为了转换成秒
			if(between<0){
				return "00:00";
			}
			long minute = between % 3600 / 60;
			long second = between % 60;
			return String.format("%02d:%02d", minute,second);
		}
	}
}
